/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

//#import "AppDelegate.h"
//
//#import <React/RCTBridge.h>
//#import <React/RCTBundleURLProvider.h>
//#import <React/RCTRootView.h>
//
//@implementation AppDelegate
//
//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//{
//  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
//  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
//                                                   moduleName:@"weizhegou"
//                                            initialProperties:nil];
//
//  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
//
//  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//  UIViewController *rootViewController = [UIViewController new];
//  rootViewController.view = rootView;
//  self.window.rootViewController = rootViewController;
//  [self.window makeKeyAndVisible];
//  return YES;
//}
//
//- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
//{
//#if DEBUG
//  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
//#else
//  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
//#endif
//}
//
//@end

// MARK: -


//
//  AppDelegate.m
//  ZCJZ
//
//  Created by Mr.han on 2018/10/26.
//  Copyright © 2018 Mr.han. All rights reserved.
//

///微信
#define WXPayKey @"wx21dd4d28d8072236"
///JPush推送
#define JPushKey @"1fb16ad7ebb2d09348f496b5"
///友盟推送
#define UMKey @"5d37f7c4570df3384e000375"
#define UMChannel @"appstore"


#import "AppDelegate.h"
#import "AppDelegate+ZCNet.h"
#import "AppDelegate+GTPush.h"
#import "MainViewController.h"
#import "PaymentManager.h"
#import <AvoidCrash.h>
#import <UMCommon/UMCommon.h>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  self.window.backgroundColor = [UIColor whiteColor];
  [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  [self setup:application launch:launchOptions];
  
  return YES;
}

-(void)setup:(UIApplication *)application launch:(NSDictionary *)launchOptions{
  //开启网络监听
  [self configNetStatus:application didFinishLaunchingWithOptions:launchOptions];
  //设置根控制器
  [self setRootVC];
  //设置推送
  [self configGTPushWithOption:launchOptions];
  //初始化第三方
  [self registThirdSDKConfig];
  [AvoidCrash makeAllEffective];
}

- (void)setRootVC {
  MainViewController *vc = [[MainViewController alloc] init];
  self.window.rootViewController = vc;
  [self.window makeKeyAndVisible];
}

- (void)autoLogin {

}

- (void)registThirdSDKConfig {
  //微信
  [WXApi registerApp:WXPayKey];
  //友盟统计
  [UMConfigure initWithAppkey:UMKey channel:UMChannel];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
  
}


// MARK: - OPEN
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  if ([url.host isEqualToString:@"safepay"]) {
    //跳转支付宝钱包进行支付，处理支付结果
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
      [[PaymentManager sharedManager] setAliPayCallback:resultDic];
    }];
    return YES;
  } else {
    return [WXApi handleOpenURL:url delegate:[PaymentManager sharedManager]];
  }
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  if ([url.host isEqualToString:@"safepay"]) {
    //跳转支付宝钱包进行支付，处理支付结果
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
      [[PaymentManager sharedManager] setAliPayCallback:resultDic];
    }];
    return YES;
  } else {
    return [WXApi handleOpenURL:url delegate:[PaymentManager sharedManager]];
  }
}

// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
  if ([url.host isEqualToString:@"safepay"]) {
    //跳转支付宝钱包进行支付，处理支付结果
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
      NSLog(@"result = %@",resultDic);
      [[PaymentManager sharedManager] setAliPayCallback:resultDic];
    }];
    return YES;
  } else {
    return [WXApi handleOpenURL:url delegate:[PaymentManager sharedManager]];
  }
}

@end



